/**
 * Created by ZFL on 2018/1/17.
 */
function appInit() {
    PageInit();
}
function PageInit () {
    everyoneBuy();//大家都在买
    infinite();//滚动加载
}
//大家都在买
var pageNum=1;
var vm = new Vue({
    el:"#app",
    data:{
        goodsData:[]
    },
    methods:{
        cartView:function () {
            //console.log('holle word');
        }
    }
});

function everyoneBuy() {
    $.ajaxHandler({
            model: function () {
                var obj={};
                obj.pageNum=pageNum;
                obj.pageSize=10;
                if(com_obj.userId && com_obj.userId>0){
                    obj.userId=com_obj.userId;
                }
                return obj;
            },
            visibleTime:200,
            dataType: "json",
            api: 'yg_baijiaappgoods/goods/goodsHotSales',
            success: function (result) {
                //console.log(result);
                if (result.code == 10000) {
                    var data = result.data.list;
                    if(data.length>0){
                        $.each(data,function (index,item) {
                            var obj={};
                            obj.goodNavigateImage=''+item.goodNavigateImage;
                            obj.name=item.name;
                            obj.href='/b2c/goods/goods.html?goodsId='+item.goodsId+'';
                            obj.lowestPrice=divideNumber(item.lowestPrice,100);
                            vm.goodsData.push(obj);
                        });
                    }else {
                        if(pageNum > 1){
                            YDUI.dialog.loading.close();
                            YDUI.dialog.toast('加载完啦~', 'none', 1000);
                            loading =  true;
                        }
                    }
                }else {
                    YDUI.dialog.toast(result.message, 'none', 1000);
                }

            }
        }
    );
}

//滚动加载
var loading=false;
function infinite() {
    $(document.body).infinite().on("infinite", function() {
        if(loading) return;
        loading = true;
        setTimeout(function() {
            YDUI.dialog.loading.close();
            loading = false;
            pageNum++;
            everyoneBuy();
        },1000);   //模拟延迟
    });
}
